 //Initialize Select2 Elements

$(".select1").select2();



 reload();

function reload(){
	var limit = 100;
	var developerId = $("#developerId").val();
	
	
	var param = {
		developerId : developerId,	
	}
	loading.show();
	$.ajax({
		url:'/api/getPrivileges',
		type:'GET',
		data:param
	}).done(function(res){
		loading.hide();
		var result = res.value;
		console.log(result);
		var pagefn = doT.template($('#tableDetail01').text());
	    $('#tableList').html(pagefn(result));
	    
	   
        
	}).fail(function(res){
		toast.show(res.errorMsg);
	})
}

function addPri(){
var developerId = $("#developerId").val();
var apiId = $("#apiId").val();
var throttledCntBySec = $("#secTimes").val();
if(apiId==null||apiId==''){
	alert("请选择api");
	return;
}
if(throttledCntBySec!=null&&throttledCntBySec!=''&&!/^\d+$/.test(throttledCntBySec)){
	alert("流量上限格式不正确");
	return;
}
	cancel('bg');
	var param = {
		developerId : developerId,	
		apiId:apiId,
		throttledCntBySec:throttledCntBySec
	}
	loading.show();
		$.ajax({
			url:'/api/insertPrivilege',
			type:'POST',
			data:param
		}).done(function(res){
			loading.hide();
			if(res.success){
				toast.show("操作成功");
				 $("#apiId").val('');
				 $("#throttledCntBySec").val('');
				reload();
			}else{
				toast.show(res.errorMsg);
			}
		}).fail(function(res){
			loading.hide();
			toast.show(res.errorMsg);
		})
}

function deleteIp(id,apiId){
	getModal.show({content:'确定删除？',cb_l:function(){return deleteIpCb(id,apiId)}});
}



function deleteIpCb(id,apiId){
	var developerId = $("#developerId").val();
	var param = {
		id:id,
		developerId:developerId,
		apiId:apiId
	}
	console.log(param)
	$.ajax({
		url:'/api/deletePrivilegeById',
		type:'POST',
		data:param
	}).done(function(res){
		if(res.success){
			toast.show("操作成功");
			reload(1);
		}else{
			toast.show(res.errorMsg);
		}
	}).fail(function(res){
		toast.show(res.errorMsg);
	})
}




